#include <iostream>
#include <fstream>
#include <cstdlib>

const int SIZE = 60;

int main()
{
	using namespace std;

	char fileName[SIZE];
	ifstream inFile;

	cout << "Enter name of data file: ";
	cin.getline(fileName, SIZE);
	inFile.open(fileName);

	if (!inFile.is_open())
	{
		cout << "Could not open the file " << fileName << endl;
		cout << "Program terminating..." << endl;
		system("pause");
		exit(EXIT_FAILURE);
	}

	double value;
	double sum = 0.0;
	int count = 0;

	while (inFile >> value)
	{
		++count;
		sum += value;
	}

	if (inFile.eof())
	{
		cout << "End of file reached." << endl;
	}
	else if (inFile.fail())
	{
		cout << "Input terminated by data mismatch" << endl;
	}
	else
	{
		cout << "Input terminated for unknown reason." << endl;
	}

	if (count == 0)
	{
		cout << "No data processed." << endl;
	}
	else
	{
		cout << "Items read: " << count << endl;
		cout << "Sum: " << sum << endl;
		cout << "Average: " << sum / count << endl;
	}

	inFile.close();
	system("pause");

	return 0;
}